package com.koron.car.web.authorized.controller;

import com.alibaba.fastjson.JSON;
import com.koron.bean.base.Response;
import com.koron.car.web.authorized.bean.entity.DelimitChange;
import com.koron.car.web.authorized.service.DelimitChangeService;
import com.koron.common.core.config.ThreadLocalContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (WCmDelimitApply)表控制层
 *
 * @author twcao
 * @since 2022-03-31 11:24:56
 */
@Slf4j
@RestController
@RequestMapping("/delimit/change")
@Api(tags = "车辆编制-编制变更")
public class DelimitChangeController {

    /**
     * 服务对象
     */
    @Resource
    private DelimitChangeService changeService;

    @GetMapping("/getDelimitNum")
    @ApiOperation("获取定编号")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "applyId", value = "申请id", required = true),
            @ApiImplicitParam(name = "type", value = "prepare_type, (delimit_manager,delimit_security)", required = true)
    })
    public Response<DelimitChange> getDelimitNum(String applyId, String type) {
        log.info("获取定编号, type = {}", type);
        DelimitChange delimitChange = ADOConnection.runTask(ThreadLocalContext.get().getCurrDs(), changeService, "getDelimitNum", DelimitChange.class, applyId, type);
        return Response.ok(delimitChange);
    }

    @PostMapping("/insert")
    @ApiOperation("新增或更新编制变更")
    public Response<DelimitChange> insert(@RequestBody DelimitChange change) {
        log.info("新增或更新编制变更， change = {}", JSON.toJSONString(change));
        DelimitChange bean = ADOConnection.runTask(ThreadLocalContext.get().getCurrDs(), changeService, "insert", DelimitChange.class, change);
        return Response.ok(bean);
    }

    @GetMapping("/deleteById")
    @ApiOperation("根据id删除编制变更")
    public Response<Boolean> delete(@RequestParam String id) {
        log.info("根据id删除编制变更， id = {}", id);
        Boolean flag = ADOConnection.runTask(ThreadLocalContext.get().getCurrDs(), changeService, "deleteById", Boolean.class, id);
        return Response.ok(flag);
    }
}
